package com.ubi.core.utils;

import com.ubi.core.utils.converter.IntegerConverter;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by pro on 2017/3/10.
 */
public class ConstellationUtil {

    private final static int[] dayArr = new int[] { 20, 19, 21, 20, 21, 22, 23,
            23, 23, 24, 23, 22 };

    private final static String[] constellationArr = new String[] { "摩羯座",
            "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座",
            "天蝎座", "射手座", "摩羯座" };

    public static String getConstellation(int month, int day) {
        return day < dayArr[month - 1] ? constellationArr[month - 1] : constellationArr[month];
    }

    public static String getConstellation(Date date){
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(date);
        return getConstellation(date.getMonth(),date.getDay());
    }

    public static String getConstellation(String dateStr){
        if(StringUtils.isNotBlank(dateStr)){
            String[] dataArray=dateStr.split("-");
            if(dataArray.length!=3){
                throw new RuntimeException("system.fail.dataFormat.error");
            }
            return getConstellation(Integer.parseInt(dataArray[1]),Integer.parseInt(dataArray[2]));
        }
        return null;
    }
}
